class ArgNotDefinedError(Exception):
    ...


class KeywordNotFoundError(Exception):
    ...


class CommandParser:
    def __init__(self, roxy):
        self.roxy = roxy
        self.command_dict = {}

    def append_command(self, command, func, args=None):
        if args is None:
            args = []
        self.command_dict[command] = [func, args]

    def run_command(self, command):
        if command[0] == "/":
            command = command[1:]
        # /音乐 -名称=a -时间=now
        if " " in command:
            commands = command.split(" ")
            command_name = commands[0]
            command_args = {}
            for i in commands[1:]:
                if i[0] == "-":
                    if "=" in i:
                        arg_name = i[1:].split("=")[0]
                        arg_value = i[1:].split("=")[1]
                        if arg_name in self.command_dict[command_name][1]:
                            command_args[arg_name] = arg_value
                        else:
                            raise KeywordNotFoundError(f"关键字<{arg_name}>从未被定义或没找到！请检查定义时的参数列表！")
                    else:
                        arg_name = i[1:]
                        if arg_name in self.command_dict[command_name][1]:
                            command_args[arg_name] = True
                        else:
                            raise KeywordNotFoundError(f"关键字<{arg_name}>从未被定义或没找到！请检查定义时的参数列表！")
                else:
                    raise ArgNotDefinedError(f"参数<{i}>从未被定义，请检查拼写......")

            self.command_dict[command_name][0](command_args)
        else:
            self.command_dict[command][0]()


if __name__ == "__main__":
    cp = CommandParser()
    cp.append_command("dog", print_dog_name, ["name", "kill"])
    cp.append_command("关机", lambda: print("关机命令！"), )

    cp.run_command("/dog -name=kate -kill")
    cp.run_command("/关机 -时间=现在")
